package com.erlang.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description：处理http的各种请求方式
 */
@Controller
@RequestMapping(value = "doMethod")
public class DoMethodController {

    /**
     * @Description get方式
     * method指定访问方式
     */
    @RequestMapping(value = "getMethod",method = RequestMethod.GET)
    public ModelAndView getMethod(){
        //构建对象视图对象
        ModelAndView modelAndView = new ModelAndView();
        //指定视图
        modelAndView.setViewName("succeed");
        //传递参数，接受map对象
        Map<String,Object> map = new HashMap<>();
        map.put("content", "getMethod");
        modelAndView.addAllObjects(map);
        return modelAndView;

    }

    /**
     * @Description post方式
     */
    @RequestMapping(value = "postMethod",method = RequestMethod.POST)
    public ModelAndView postMethod(){
        //构建对象视图对象
        ModelAndView modelAndView = new ModelAndView();
        //指定视图
        modelAndView.setViewName("succeed");
        //传递参数，接受map对象
        Map<String,Object> map = new HashMap<>();
        map.put("content", "postMethod");
        modelAndView.addAllObjects(map);
        return modelAndView;
    }
}
